package com.fowo.api.om.controller;

import com.fowo.api.common.model.R;
import com.fowo.api.om.model.OmFileMigratePo;
import com.fowo.api.om.model.OmFileMigrateResult;
import com.fowo.api.om.model.OmFunction;
import com.fowo.api.om.service.OmFileService;
import com.fowo.api.sys.acm.AsyncControllerMethod;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 运维文件接口
 */
@PreAuthorize("@am.canAccess('sysOm')")
@Tag(name = "OmFile", description = "运维文件控制器")
@RequestMapping("/api/om/file")
@RestController
public class OmFileController {
    @Resource
    private OmFileService omFileService;

    /**
     * 获取运维接口功能清单
     */
    @Operation(summary = "获取运维接口功能清单")
    @GetMapping
    public List<OmFunction> info() {
        return List.of(
                new OmFunction("POST", "/om/file/migrate", "附件迁移接口")
        );
    }

    /**
     * 附件迁移
     * @param migratePo 附件迁移请求
     * @return 迁移结果
     */
    @AsyncControllerMethod
    @Operation(summary = "附件迁移")
    @PostMapping("migrate")
    public R<OmFileMigrateResult> migrate(@RequestBody OmFileMigratePo migratePo) {
        return R.data(() -> omFileService.migrate(migratePo));
    }
}
